<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class EntryController extends Controller
{
    public function __construct()
    {
        $this->middleware('admin')->except(
            ['loginForm','login']
        );
    }


//  后台登录界面
    public function loginForm()
    {
        return view('admin.entry.login');
    }

//  后台登录方法
    public function login(Request $request)
    {
        $status=\Auth::guard('admin')->attempt([
           'username'=>$request->input('username'),
           'password'=>$request->input('password'),
        ]);
        if ($status){
            session()->flash('success','用户登录成功');
            return redirect('/admin/index');
        }
        session()->flash('error','用户登录失败');
        return back();
    }
//  后台退出
    public function logout(){
        \Auth::guard('admin')->logout();
        session()->flash('success','用户退出成功');
        return redirect('/admin');
    }


//  后台界面
    public function index(){
        return view('admin.entry.index');
    }
}
